<!--
 * @Author: Dorange.Wang
 * @Date: 2021-11-12 10:48:01
 * @LastEditors: your name
 * @LastEditTime: 2021-11-16 10:29:53
 * @Description: file content
-->
<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="800px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{$t('sys.model_field')}}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <div class="pl30 pr30">
      <el-table
        ref="table"
        :data="tableData"
        style="width: 100%"
        current-row-key="id"
        stripe
        border
        v-loading="loading"
      >
        <el-table-column prop="code" :label="$t('sys.code')" width="240">
          <template slot-scope="scope">
            <span class="mr5">{{ scope.row.code }}</span>
            <el-button
              type="text"
              @click="copy(scope.row.code)"
              icon="el-icon-document-copy"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column prop="name" :label="$t('sys.full_name')" />
        <el-table-column prop="title" :label="$t('sys.type')" width="120">
          <template slot-scope="scope">
            {{ scope.row.builtIn ? "--" : scope.row.type | fieldDataType }}
          </template>
        </el-table-column>
      </el-table>
      <div class="tr mt24">
        <x-pagination
          :total="total"
          :pageSize.sync="pageData.pageSize"
          :pageNo.sync="pageData.pageNo"
          @search="loadFields()"
        />
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getHmentitymodelPageList } from '@/apis/paas/HmEntityModelController.js'
import { copy } from '@/utils/util'

export default {
  data () {
    return {
      loading: false,
      showVisible: false,
      pageData: {
        pageSize: 10,
        pageNo: 1
      },
      total: 0,
      tableData: [],
      options: {}
    }
  },

  methods: {
    copy,
    open (options = {}) {
      this.tableData = []
      this.pageData = {
        pageSize: 10,
        pageNo: 1
      }
      this.showVisible = true
      this.options = { ...options }
      this.loadFields()
    },

    close () {
      this.showVisible = false
    },

    async loadFields (pageNo = this.pageData.pageNo) {
      this.loading = true
      try {
        const res = await getHmentitymodelPageList({
          ...this.pageData,
          pageNo,
          modelId: this.options.modelId
        })
        this.tableData = res.data
        this.total = res.totalCount
        this.pageData = {
          pageSize: res.pageSize,
          pageNo: res.pageNo
        }
      } catch (err) {
      } finally {
        this.loading = false
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
